﻿using MediatR;
using PublicClass;
using S.Eartag.Infrastructure.Impl;
using S.Eartag.Infrastructure.Interface;
using S.Eartag.Read.API.Application.Command.SheepFileConditionCommand;

namespace S.Eartag.Read.API.Application.CommandHandlers.SheepFileConditionCommandHandler
{
    public class SheepFileConditionEardCommandHandler : IRequestHandler<SheepFileConditionEardCommand, List<SelectList>>
    {
        private readonly ISheepFileRepository sheepFileRepository;

        public SheepFileConditionEardCommandHandler(ISheepFileRepository sheepFileRepository)
        {
            this.sheepFileRepository = sheepFileRepository;
        }
        public async Task<List<SelectList>> Handle(SheepFileConditionEardCommand request, CancellationToken cancellationToken)
        {
            var info =await sheepFileRepository.GetValues(x=>!x.IsDel);
            List<SelectList> result = new List<SelectList>();
            foreach (var item in info)
            {
                result.Add(new SelectList
                {
                    Id = item.Id,
                    Name = item.EarNumber
                });
            }
            return result;
        }
    }
}
